package 链表;



public class 分割链表 {
//使用双指针思想
    public ListNode partition(ListNode head, int x) {
         ListNode pre = head;
         ListNode cur = head;
         while (cur!=null){
             if (cur.val<x){
                 int tem = cur.val;
                 cur.val = pre.val;
                 pre.val = tem;
                 //交换完后向前一步
                 pre=pre.next;
             }
             cur=cur.next;
         }
         return head;
    }
}
